package com.sss.support.service;

import java.io.File;
import java.util.List;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sss.gsb.orm.model.DeadMan;
import com.sss.gsb.orm.repository.DeadManRepository;
import com.sss.gsb.orm.repository.InsuranceRepository;
import com.sss.support.poi.transform.DeadManModelTransformer;

@Service
public class GSBDataImporter implements DataImportService {

	@Autowired DeadManRepository deadManRepo;
	@Autowired InsuranceRepository insuranceRepo;
	
	private static final Logger log = org.slf4j.LoggerFactory.getLogger(GSBDataImporter.class);
	
	@Transactional
	@Override
	public void importDeadManToDB(File file,Integer start,Integer end)
			throws DataImportException, ContentNotAllowedException {
		
		try{
			DeadManModelTransformer trans = new DeadManModelTransformer(file, start, end);
			List<DeadMan> deadManList = trans.doTransform();
			log.info("The number of data transformed is :: {}",deadManList.size());
			
			log.info("Start inserting all data into database ");
			for(DeadMan d : deadManList){
				deadManRepo.insert(d);
			}
			log.info("Finish inserting all data into database ");
			
		}catch(Exception ex){
			throw new DataImportException(ex);
		}
	}

	@Transactional
	@Override
	public void importInsuranceToDB(File file, Integer start, Integer end)
			throws DataImportException, ContentNotAllowedException {
		throw new UnsupportedOperationException("Waiting for specification....");
//		try{
//			InsuranceModelTransformer trans = new InsuranceModelTransformer(file, start, end);
//			List<Insurance> insuranceList = trans.doTransform();
//			log.info("The number of data transformed is :: {}",insuranceList.size());
//			
//			log.info("Start inserting all data into database ");
//			for(Insurance d : insuranceList){
//				insuranceRepo.insert(d);
//			}
//			log.info("Finish inserting all data into database ");
//			
//		}catch(Exception ex){
//			throw new DataImportException(ex);
//		}
	}
	

	
}
